package com.qzsoft.zhjd.server.modules.ludong.asphalt.controller;


import com.qzsoft.zhjd.server.common.utils.MapToBeanUtils;
import com.qzsoft.zhjd.server.common.utils.R;
import com.qzsoft.zhjd.server.modules.ludong.asphalt.entity.SievingDataEntity;
import com.qzsoft.zhjd.server.modules.ludong.asphalt.service.SievingDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 *
 * 功能描述:沥青筛分数据表
 * @author jiangyafei
 * @email jiangyf_sd@163.com
 * @date 2020-06-09 11:17:30
 */
@Slf4j
@RestController
@RequestMapping("datacollect/asphalt/sievingdata")
public class SievingDataController {

    @Autowired
    private SievingDataService sievingDataService;

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestParam Map<String,Object> params){
        log.info("沥青筛分数据表==="+params.toString());
        if(params != null && params.size()>0 ){
            Map<String,Object> map = MapToBeanUtils.toReplaceKeyLow(params);
            try{
                SievingDataEntity sievingDataEntity = MapToBeanUtils.mapToObject(map,SievingDataEntity.class);
                if(StringUtils.isNotBlank(sievingDataEntity.getId())){
                    sievingDataService.removeById(sievingDataEntity.getId());
                    sievingDataService.save(sievingDataEntity);
                    return R.ok();
                }
            }catch (Exception e){
                return R.error(400,e.getMessage());
            }
        }
        return R.error(400,"数据为空！");
    }


}
